package org.jadapter.guice;

import java.util.Set;

import org.jadapter.Adapter;
import org.jadapter.registry.TransientAdapterRegistry;

import com.google.inject.Inject;
import com.google.inject.Injector;

/**
 * Adapter registry implementation that performs Guice injection
 * after instantiation
 */
public class GuiceTransformerRegistry extends TransientAdapterRegistry {

	private Injector injector;

	@Inject
	public GuiceTransformerRegistry(Injector injector, Set<Adapter> adapters) {
		this.injector = injector;
		for(Adapter<?, ?> adapter : adapters) {
			register(adapter);
		}
	}
	
	public <T> T transform(Object context, Class<T> type) {
		T instance = super.transform(context, type);
        injector.injectMembers(instance);
        return instance;
    }
	
}